import QtQuick 1.0
import com.meego 1.0
import "Forum.js" as ForumUtil
import "database.js" as DataBaseUtil
ListModel {
    id: container

    function loadClubList(forumId,clupType,currentIndex){

       var doc = new XMLHttpRequest();
        doc.onreadystatechange = function() {
            if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
            } else if (doc.readyState == XMLHttpRequest.DONE) {
                var a = doc.responseXML.documentElement;

              for(var index=0;index<a.childNodes[1].childNodes.length;index++){

                 if("Name"==a.childNodes[1].childNodes[index].nodeName){
                     forum_main.forumName = a.childNodes[1].childNodes[index].childNodes[0].nodeValue;
                 }else if("Simple"==a.childNodes[1].childNodes[index].nodeName){
                      forum_main.simpleName=a.childNodes[1].childNodes[index].childNodes[0].nodeValue;
                 }else if("Image"==a.childNodes[1].childNodes[index].nodeName){

                     forum_main.forumMainImageUrl=a.childNodes[1].childNodes[index].childNodes[0].nodeValue;

                 }else if("TotalPage"==a.childNodes[1].childNodes[index].nodeName){


                     var totalPage =a.childNodes[1].childNodes[index].childNodes[0].nodeValue;
                     if(totalPage=="0"){
                         totalPage="1";
                     }
                     forum_main.forumPageNum =totalPage;

                 }else if("ClubSeries"==a.childNodes[1].childNodes[index].nodeName){
                     var cluSeries="";
                     for(var c=1;c < a.childNodes[1].childNodes[index].childNodes.length;c=c+2){
                         if(a.childNodes[1].childNodes[index].childNodes[c].childNodes.length>0){
                             if(a.childNodes[1].childNodes[index].childNodes[c].childNodes[1].childNodes.length >0){
                                 if(c<5)
                                    cluSeries +=a.childNodes[1].childNodes[index].childNodes[c].childNodes[1].childNodes[0].nodeValue+"   ";
                             }
                         }
                     }
                     forum_main.clubSeriesName = cluSeries;

                 }else if("ClubMaster"==a.childNodes[1].childNodes[index].nodeName){
                     var clubMaster="";

                     for(var d=1;d < a.childNodes[1].childNodes[index].childNodes.length;d=d+2){
                         if(a.childNodes[1].childNodes[index].childNodes[d].childNodes.length>0){
                             if(d<5)
                              clubMaster +=a.childNodes[1].childNodes[index].childNodes[d].childNodes[1].childNodes[0].nodeValue+"   ";
                         }
                       }

                     forum_main.clubMasterName = clubMaster;


                 }else if("UpTopics"==a.childNodes[1].childNodes[index].nodeName){
                     var upTopicId ="";var uptitle  =""; var upreplyCount ="0"; var upviewCount  = "0";
                     var uplastPostTime =""; var uplastPostMember  = "";   var uppostTime  = "";  var uppostMember = "";
                     var uptopicTypeName ="";

                         for(var k=1;k < a.childNodes[1].childNodes[index].childNodes.length;k=k+2){//节点<UpTopics>

                             if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[1].childNodes.length>0){
                                 upTopicId = a.childNodes[1].childNodes[index].childNodes[k].childNodes[1].childNodes[0].nodeValue;
                             }
                             if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[3].childNodes.length>0){
                                 uptitle  =   a.childNodes[1].childNodes[index].childNodes[k].childNodes[3].childNodes[0].nodeValue;
                              }
                             if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[5].childNodes.length>0){
                                 upreplyCount =a.childNodes[1].childNodes[index].childNodes[k].childNodes[5].childNodes[0].nodeValue;
                              }
                             if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[7].childNodes.length>0){
                                 upviewCount  =   a.childNodes[1].childNodes[index].childNodes[k].childNodes[7].childNodes[0].nodeValue;

                             }
                             if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[9].childNodes.length>0){
                                 uplastPostTime =a.childNodes[1].childNodes[index].childNodes[k].childNodes[9].childNodes[0].nodeValue;
                             }

                             if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[11].childNodes.length){
                                 uplastPostMember =a.childNodes[1].childNodes[index].childNodes[k].childNodes[11].childNodes[0].nodeValue;
                             }
                             if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[13].childNodes.length>0){
                                 uppostTime  =   a.childNodes[1].childNodes[index].childNodes[k].childNodes[13].childNodes[0].nodeValue;
                             }
                             if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[14].childNodes.length>0){
                                uppostMember =  a.childNodes[1].childNodes[index].childNodes[k].childNodes[14].childNodes[0].nodeValue;

                              }
                              if(a.childNodes[1].childNodes[index].childNodes[k].childNodes[16].childNodes.length>0){
                                  uptopicTypeName =a.childNodes[1].childNodes[index].childNodes[k].childNodes[16].childNodes[0].nodeValue;
                              }

                             forumClubListModel.append({"topicId":upTopicId,"topicTitle":uptitle,"replayCount":upreplyCount,"viewCount":upviewCount,"lastPostTime":uplastPostTime,"lastPostMember":uplastPostMember,"postTime":uppostTime,"postMember":uppostMember,"topicTypeName":uptopicTypeName})


                    }

                 }else if("ClubTopic"==a.childNodes[1].childNodes[index].nodeName){

                     var topicId ="";var title  ="";  var replyCount =""; var viewCount  ="";
                      var lastPostTime =""; var lastPostMember  = "";var postTime  = "";var postMember ="";
                       var topicTypeName  ="";

                        for(var n=1;n < a.childNodes[1].childNodes[index].childNodes.length;n=n+2){//节点<Clubtopic>

                         if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[1].childNodes.length>0){
                             topicId =a.childNodes[1].childNodes[index].childNodes[n].childNodes[1].childNodes[0].nodeValue;
                         }


                         if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[3].childNodes.length>0){
                             title=a.childNodes[1].childNodes[index].childNodes[n].childNodes[3].childNodes[0].nodeValue;
                         }


                         if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[5].childNodes.length>0){
                             replyCount =a.childNodes[1].childNodes[index].childNodes[n].childNodes[5].childNodes[0].nodeValue;

                         }


                         if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[7].childNodes.length>0){

                                viewCount= a.childNodes[1].childNodes[index].childNodes[n].childNodes[7].childNodes[0].nodeValue;
                         }

                          if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[9].childNodes.length>0){
                              lastPostTime=a.childNodes[1].childNodes[index].childNodes[n].childNodes[9].childNodes[0].nodeValue;
                         }

                           if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[11].childNodes.length>0){
                             lastPostMember= a.childNodes[1].childNodes[index].childNodes[n].childNodes[11].childNodes[0].nodeValue;
                         }


                         if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[13].childNodes.length>0){

                             postTime=a.childNodes[1].childNodes[index].childNodes[n].childNodes[13].childNodes[0].nodeValue;
                           }

                         if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[15].childNodes.length){
                             postMember=a.childNodes[1].childNodes[index].childNodes[n].childNodes[15].childNodes[0].nodeValue;
                          }

                          if(a.childNodes[1].childNodes[index].childNodes[n].childNodes[17].childNodes.length>0){
                              topicTypeName =a.childNodes[1].childNodes[index].childNodes[n].childNodes[17].childNodes[0].nodeValue;
                           }

                         forumClubListModel.append({"topicId":upTopicId,"topicTitle":title,"replayCount":replyCount,"viewCount":viewCount,"lastPostTime":lastPostTime,"lastPostMember":lastPostMember,"postTime":postTime,"postMember":postMember,"topicTypeName":topicTypeName})


                   }

                 }else{
                     continue;

                 }
               }
              //记录最近浏览记录
               //ForumUtil.addRecent_forum(forumId, forum_main.simpleName,forum_main.forumMainImageUrl);
              //console.log("addRectentForum:"+forumId+",name:"+forum_main.simpleName+",imageUrl:"+forum_main.forumMainImageUrl);
              DataBaseUtil.addRectentForum(forumId,forum_main.simpleName,forum_main.forumMainImageUrl,"");
            }

        }
        doc.open("GET", ForumUtil.getForumUrl(forumId,clupType,currentIndex));
        doc.send();
    }
  }

